package com.xyf.sys.mapper;

import com.xyf.sys.domain.Region;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface RegionMapper {
  
    // 插入新记录  
    @Insert("INSERT INTO sys_regions (code, name, parent_id, status, del_flag, create_by, create_time, update_by, update_time, remark)" +  
            " VALUES (#{code}, #{name}, #{parentId}, #{status}, #{delFlag}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{remark})")  
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")  
    int insert(Region region);
  
    // 根据ID删除记录  
    @Delete("DELETE FROM sys_regions WHERE id = #{id}")  
    int deleteById(Long id);  
  
    // 根据ID更新记录  
    @Update("UPDATE sys_regions SET code = #{code}, name = #{name}, parent_id = #{parentId}, status = #{status}, " +  
            "del_flag = #{delFlag}, update_by = #{updateBy}, update_time = #{updateTime}, remark = #{remark} WHERE id = #{id}")  
    int updateById(Region region);
  
    // 根据ID查询记录  
    @Select("SELECT * FROM sys_regions WHERE id = #{id}")
    Region selectById(Long id);
  
    // 查询所有记录  
    @Select("SELECT id, code ,name ,parent_id as parentId FROM sys_regions")
    List<Region> selectAll();
  
    // 根据条件查询记录（示例：根据状态查询）  
    @Select("SELECT * FROM sys_regions WHERE status = #{status}")  
    List<Region> selectByStatus(String status);
  
}